#!/bin/bash
#
# Copyright 2023 Jeff Cliff
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program at COPYING.GPL.  If not, see <https://www.gnu.org/licenses/>.
# 
#
# add this to audacity's "song change" plugin
# for PATH_TO_SCRIPT wherever you put this
# echo "%a" > /tmp/scrobblescript-artist; echo "%b" > /tmp/scrobblescript-album; echo "%T" > /tmp/scrobblescript-title; [PATH_TO_SCRIPT]/scrobble-me.sh
# in song start song end and network filename change
HOME=/home/themusicgod1
INSTANCE=shitposter.world

#echo "
TITLE=`cat /tmp/scrobblescript-title`;
#echo "ARTIST:"
ARTIST=`cat /tmp/scrobblescript-artist`;
#echo "ALBUM:"
ALBUM=`cat /tmp/scrobblescript-album`;

echo "TOKEN:"
TOKEN=`cat $HOME/.config/toot/config.json |  grep access_token | awk -F':' '{print $2}' | awk -F'"' '{print $2}'`
#echo $TOKEN
#echo $ARTIST " " $TITLE " " $ALBUM
curl -X POST \
	-d "title=$TITLE " \
	-d "album=$ALBUM " \
	-d "artist=$ARTIST " \
	-H 'Authorization: Bearer '$TOKEN \
	https://$INSTANCE/api/v1/pleroma/scrobble
